const Trans = {
  cascader: (data, value = 'id', label = 'name') => {
    let lists = [];
    for (let i in data) {
      let tmp = data[i];
      let children = tmp.children;
      let childrens = [];
      for (let j in children) {
        let jtmp = children[j];
        childrens.push({
          value: jtmp[value],
          label: jtmp[label]
        });
      }
      lists.push({
        value: tmp[value],
        label: tmp[label],
        children: childrens
      });
    }
    return lists;
  },
  options: data => {
    let type = typeof data;
    let lists = [];
    if (type === 'object') {
      for (let i in data) {
        let value = data[i];
        if (typeof value === 'object') {
          lists.push(value);
          continue;
        }
        if (/^[0-9]+$/.test(i)) {
          i = parseInt(i);
        }
        lists.push({
          value: i,
          label: data[i]
        });
      }
    }
    return lists;
  }
};

export default Trans;
